package net.hserver.sync.service;

import cn.hserver.core.ioc.annotation.Autowired;
import cn.hserver.core.ioc.annotation.Bean;
import cn.hutool.core.util.StrUtil;
import com.mybatisflex.core.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import net.hserver.sync.entity.SyncLogEntity;
import net.hserver.sync.mapper.SyncLogMapper;

@Bean
@Slf4j
public class SyncLogService {

    @Autowired
    private SyncLogMapper syncLogMapper;

    public Object list(Integer current, Integer pageSize, String keyword) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (StrUtil.isNotEmpty(keyword)) {
            queryWrapper.like(SyncLogEntity::getMessage, keyword);
        }
        queryWrapper.orderBy(SyncLogEntity::getId, false);
        return syncLogMapper.paginate(current, pageSize, queryWrapper);
    }

    public boolean delAll() {
        return syncLogMapper.deleteAll()>0;
    }
}
